<template>
  <yd-ls-layout title="webim登录" tolfurl="index.html#/test2" torgurl="./app.html">
    <yd-cell-group>
      <yd-cell-item>
        <span slot="left">手机号：</span>
        <yd-input slot="right" v-model="phone" ref="input9" required regex="mobile" placeholder="请输入手机号码"></yd-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left">密码：</span>
        <yd-input slot="right" type="password" v-model="pwd" placeholder="请输入密码"></yd-input>
      </yd-cell-item>
    </yd-cell-group>
    <yd-button-group>
      <yd-button size="large" @click.native="loginIm">登录</yd-button>
    </yd-button-group>

    <a href="webim.html#/reg">先注册</a>

    <br><br>

    <a href="webim.html#/chat">发消息</a>

  </yd-ls-layout>
</template>

<script>
  import ydLsLayout from '../../../components/yd-ls-layout.vue'
  import WebIM from '../../webimjs/Lib/WebIM'

  export default {
    name: '',
    props: {},
    data() {
        return {
          phone: '',
          pwd: ''
        }
    },
    methods: {
      loginIm () {

        var options = {
          apiUrl: WebIM.config.apiURL,
          user: 'leson',
          pwd: '123456',
          appKey: WebIM.config.appkey
        };
        WebIM.conn.open(options);
        console.log('登录成功')

      },
      sendMsg () {
        let _this = this
        console.log('send')
        // 单聊发送文本消息
        var id = WebIM.conn.getUniqueId();                 // 生成本地消息id
        var msg = new WebIM.message('txt', id);      // 创建文本消息
        msg.set({
          msg: 'message content--son4',                  // 消息内容
          to: 'son',                          // 接收消息对象（用户id）
          roomType: false,
          success: function (id, serverMsgId) {


            console.log('send private text Success!');
          },
          fail: function(e){
            console.log("Send private text error");
          }
        });
        msg.body.chatType = 'singleChat';
        WebIM.conn.send(msg.body);
      }
    },
    mounted() {

    },
    components: { ydLsLayout }


  }
</script>
<style>

</style>
